﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI;

using DevExpress.Web.ASPxHeadline;

using LMD.Lib.DataClass;
using LMD.Constant;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;
using LMD.Lib.Controls;

/// <summary>
/// Summary description for CDManager
/// </summary>
public static class CDManager
{
    public static String BuildEditor_CompanyList()
    {
        String sxOutput = String.Empty;
        String sxOTFComboCustomer = CustomControls.Create_OTFComboBox(
            KCD.CUSTOMER_ID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, String.Empty, "SelectCompany()");
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", sxOTFComboCustomer);

        return sxOutput;
    }
    public static String BuildEditor_CDData(this CDData cdData, String sxCompanyName, int iCustomerID)
    {    
        String sxOutput = String.Empty;

        String sxConfigUploadControl = CustomControls.BuildEditor_FileUpload(KCD.CONFIG_FILE_ID,
            KFileHandler.CD.CONFIGURATION, null, KControl.INPUT_ID + "_" + KCD.CONFIG_FILE_ID, TextboxType.FileUpload);
        String sxDatekUploadControl = CustomControls.BuildEditor_FileUpload(KCD.DATEK_FILE_ID,
            KFileHandler.CD.DATEK, null, KControl.INPUT_ID + "_" + KCD.DATEK_FILE_ID, TextboxType.FileUpload);
        String sxEvaluasiUploadControl = CustomControls.BuildEditor_FileUpload(KCD.EVALUASI_FILE_ID,
            KFileHandler.CD.EVALUASI, null, KControl.INPUT_ID + "_" + KCD.EVALUASI_FILE_ID, TextboxType.FileUpload);
        String sxLOVNetwork = CustomControls.Create_OTFComboBox(KCD.NETWORK, 
            KLOV.ConfigDatek.NETWORK, "", "", TextboxType.Empty, iCustomerID.ToString(), "SelectNetworkInfo()");

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", sxCompanyName);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Configuration File", sxConfigUploadControl);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Datek File", sxDatekUploadControl);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Evaluation File", sxEvaluasiUploadControl);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Network No", sxLOVNetwork);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KCD.INFO, KControl.INPUT_ID, "Info", null);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KCD.NOTE, KControl.INPUT_ID, "Note", null, TextboxType.Notes);
        sxOutput += "<input type=\"button\" id=\"btnCancel\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"";
        sxOutput += " onclick=\"cancel();\" value=\"cancel\" />";
        sxOutput += "<input type=\"button\" id=\"btn\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"";
        sxOutput += " onclick=\"CD_New('" + iCustomerID.ToString() + "');\" value=\"save\" />";
        sxOutput += "<div id=\"load\"></div>";
        return sxOutput;
    }

    public static String BuildFieldSet_UpdateCDData(CDData cdData)
    {
        String sxOutput = String.Empty;
        if (cdData != null)
        {
            if (cdData.iCustomerID > 0)
            {
                cdData.sxCompanyName = DBQuery.CustomerTable.GetCompanyNameByID(cdData.iCustomerID);
                sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", cdData.sxCompanyName);
            }
            if (cdData.iConfigFileID > 0)
            {
                String sxConfigFileName = DBQuery.FileUploadTable.GetFileNameById(cdData.iConfigFileID);
                String sxConfigLink = CustomControls.Build_FileUploadResult(KCD.CONFIG_FILE_ID, null,
                    KFileHandler.CD.CONFIGURATION, KControl.INPUT_ID,
                    cdData.iConfigFileID.ToString(), sxConfigFileName);

                sxOutput += CustomControls.BuildFieldSet_PairedLabel("Configuration File", sxConfigLink);
            }
            else
            {
                String sxConfigUploadControl = CustomControls.BuildEditor_FileUpload(KCD.CONFIG_FILE_ID,
                    KFileHandler.CD.CONFIGURATION, null, KControl.INPUT_ID + "_" + KCD.CONFIG_FILE_ID, TextboxType.FileUpload);
                sxOutput += CustomControls.BuildFieldSet_PairedLabel("Configuration File", sxConfigUploadControl);
            }
            if (cdData.iDatekFileID > 0)
            {
                String sxDatekFileName = DBQuery.FileUploadTable.GetFileNameById(cdData.iDatekFileID);
                String sxDatekLink = CustomControls.Build_FileUploadResult(KCD.DATEK_FILE_ID, null,
                    KFileHandler.CD.DATEK, KControl.INPUT_ID,
                    cdData.iDatekFileID.ToString(), sxDatekFileName);
                sxOutput += CustomControls.BuildFieldSet_PairedLabel("Datek File", sxDatekLink);
            }
            else
            {
                String sxDatekUploadControl = CustomControls.BuildEditor_FileUpload(KCD.DATEK_FILE_ID,
                    KFileHandler.CD.DATEK, null, KControl.INPUT_ID + "_" + KCD.DATEK_FILE_ID, TextboxType.FileUpload);
                sxOutput += CustomControls.BuildFieldSet_PairedLabel("Datek File", sxDatekUploadControl);
            }
            if (cdData.iEvaluasiFileID > 0)
            {
                String sxEvaluasiFileName = DBQuery.FileUploadTable.GetFileNameById(cdData.iEvaluasiFileID);
                String sxEvaluasiLink = CustomControls.Build_FileUploadResult(KCD.EVALUASI_FILE_ID, null,
                    KFileHandler.CD.EVALUASI, KControl.INPUT_ID,
                    cdData.iEvaluasiFileID.ToString(), sxEvaluasiFileName);

                sxOutput += CustomControls.BuildFieldSet_PairedLabel("Evaluation File", sxEvaluasiLink);
            }
            else
            {
                String sxEvaluasiUploadControl = CustomControls.BuildEditor_FileUpload(KCD.EVALUASI_FILE_ID,
                    KFileHandler.CD.EVALUASI, null, KControl.INPUT_ID + "_" + KCD.EVALUASI_FILE_ID, TextboxType.FileUpload);
                sxOutput += CustomControls.BuildFieldSet_PairedLabel("Evaluation File", sxEvaluasiUploadControl);
            }
        }
        String sxLOVNetwork = CustomControls.Create_OTFComboBox(KCD.NETWORK,
            KLOV.ConfigDatek.NETWORK, "", "", TextboxType.Empty, cdData.iCustomerID.ToString(), "SelectNetworkInfo()");
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Network No", sxLOVNetwork);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KCD.INFO, KControl.INPUT_ID, "Info", cdData.sxInfo);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KCD.NOTE, KControl.INPUT_ID, "Note", cdData.sxNote,TextboxType.Notes);
        sxOutput += "<input type=\"button\" id=\"btnCancel\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"";
        sxOutput += " onclick=\"cancel();\" value=\"cancel\" />";
        sxOutput += "<input type=\"button\" id=\"btn\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"";
        sxOutput += " onclick=\"edit('" + cdData.iCustomerID.ToString() + "','" + cdData.iCDID.ToString() + "');\" value=\"save\" />";
        sxOutput += "<div id=\"load\"></div>";
        
        return sxOutput;
    }

    public static String BuildTable_CDReportByClass(DataTable dtReport)
    {
        String sxOutput = String.Empty;

        sxOutput = 
           "<table style=\"width:100%;\" class=\"reportTable\">" +
                "<tr>" +
                    "<th style=\"width:15%;\">KELAS</th>" +
                    "<th style=\"width:15%;\">JENIS</th>" +
                    "<th style=\"width:50%;\">STATISTIK</th>" +
                    "<th style=\"width:10%;\">TOTAL FILE</th>" +
                    "<th style=\"width:10%;\">TOTAL PELANGGAN</th>" +
                "</tr>" ;

        foreach (DataRow dr in dtReport.Rows)
        {
            sxOutput += String.Format(
                "<tr>" +
                    "<td class=\"reportTableClass\" rowspan=\"3\" align=\"left\">{0}</td>" +
                    "<td><a class=\"lnk\" href=\"CDReport.aspx?mode={0}_KONFIG\">Konfig</a></td>" +
                    "<td><div style=\"width:{1}%; background-color:#00BB00;\">&nbsp;</div>{1}%</td>" +
                    "<td align=\"center\">{2}</td>" +
                    "<td rowspan=\"3\" align=\"center\">{3}</td>" +
                "</tr>" +
                "<tr>" +
                    "<td><a class=\"lnk\" href=\"CDReport.aspx?mode={0}_DATEK\">Datek</a></td>" +
                    "<td><div style=\"width:{4}%; background-color:#008800;\">&nbsp;</div>{4}%</td>" +
                    "<td align=\"center\">{5}</td>" +
                "</tr>" +
                "<tr>" +
                    "<td><a class=\"lnk\" href=\"CDReport.aspx?mode={0}_EVALUASI\">Evaluasi</a></td>" +
                    "<td><div style=\"width:{6}%; background-color:#005500;\">&nbsp;</div>{6}%</td>" +
                    "<td align=\"center\">{7}</td>" +
                "</tr>",
                dr["COMPANY_CLASS"].ToString(),
                dr["PERSEN_KONFIG"].ToString(),
                dr["JUMLAH_KONFIG"].ToString(),
                dr["JUMLAH_PELANGGAN"].ToString(),
                dr["PERSEN_DATEK"].ToString(),
                dr["JUMLAH_DATEK"].ToString(),
                dr["PERSEN_EVAL"].ToString(),
                dr["JUMLAH_EVAL"].ToString());
        }
        sxOutput +=       
            "</table>";

        return sxOutput;
    }

    //add by rista
    public static String BuildEditor_CDList()
    {
        String sxOutput = String.Empty;

        String sxStartDate = CustomControls.Create_TextBox(KCV.START,
            KControl.INPUT_ID, String.Empty, true, TextboxType.Date);
        String sxEndDate = CustomControls.Create_TextBox(KCV.END,
            KControl.INPUT_ID, String.Empty, true, TextboxType.Date);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Start Date", sxStartDate);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("End Date", sxEndDate);
        sxOutput +=
            "<dt>&nbsp;</dt><dd><input type=\"button\" id=\"btnFilter\" class=\"btn\"" +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"Filter();\" value=\"FILTER\" />" +
            "<input type=\"button\" id=\"btnAll\" class=\"btn\"" +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"ShowAll();\" value=\"SHOW ALL\" /></dd> " +
            "<div id=\"load\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"></div>";
        return sxOutput;
    }
}
